package com.leyou.item.web;


import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import com.leyou.item.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/spec")
public class SpecificationController {

    @Autowired
    SpecificationService specificationService;

    @RequestMapping("/groups/{cid}")
    public ResponseEntity<List<SpecGroup>> queryGroupByCid(@PathVariable("cid") Long cid){

        return ResponseEntity.ok(specificationService.queryGroupByCid(cid));
    }

    /***
     * 根据组id查询参数
     * @param gid 规格组id
     * @param cid 分类id
     * @return
     */

    @GetMapping("params")
    public ResponseEntity<List<SpecParam>> queryByGid(@RequestParam(value = "gid",required = false) Long gid,
                                                      @RequestParam(value = "cid",required = false) Long cid,
                                                      @RequestParam(value = "searching",required = false) Boolean searching
    ){

        return ResponseEntity.ok(specificationService.queryParamList(gid,cid,searching));

    }





}
